package com.itheima.d2_reflect;


import org.junit.Test;

import java.lang.reflect.Field;

public class Test3Field {
    @Test
    public void testGetFields() throws Exception {
        Class c=Cat.class;

        Field[] fields = c.getDeclaredFields();
        for (Field field : fields) {
            System.out.println(field.getName()+"==>"+field.getType());

        }

        Field fname = c.getDeclaredField("name");
        System.out.println(fname.getName()+"==>"+fname.getType());

        Field fage = c.getDeclaredField("age");
        System.out.println(fage.getName()+"==>"+fage.getType());

        Cat cat =new Cat();
        fname.setAccessible(true);
        fname.set(cat,"加菲猫");

        System.out.println(cat);

        String name =(String) fname.get(cat);

        System.out.println(name);


    }


}
